//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.diboot.iam.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.diboot.core.binding.query.BindQuery;
import com.diboot.core.binding.query.Comparison;
import com.diboot.core.entity.BaseEntity;
import com.diboot.core.util.JSON;
import com.diboot.core.util.S;
import com.diboot.core.util.V;
import com.diboot.iam.entity.route.RouteMeta;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.Length;

import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

@TableName("dbt_iam_resource")
public class IamResource extends BaseEntity<String> {
    private static final long serialVersionUID = -6133621123987747250L;
    @JsonIgnore
    @TableField
    private String tenantId;
    @TableField
    private String appModule;
    @TableField
    private String parentId;
    @TableField
    private @NotNull(
            message = "展现类型不能为空"
    ) @Length(
            max = 20,
            message = "展现类型长度应小于20"
    ) String displayType;
    @BindQuery(
            comparison = Comparison.LIKE
    )
    private @NotNull(
            message = "显示名称不能为空"
    ) @Length(
            max = 100,
            message = "显示名称长度应小于100"
    ) String displayName;
    private String displayNameI18n;
    @TableField
    private @Length(
            max = 200,
            message = "路由地址长度应小于200"
    ) String routePath;
    @TableField
    private @NotNull(
            message = "前端资源编码不能为空"
    ) @Length(
            max = 50,
            message = "前端资源编码长度应小于50"
    ) String resourceCode;
    @TableField
    private @Length(
            max = 500,
            message = "权限编码长度应小于500"
    ) String permissionCode;
    @TableField
    private @Length(
            max = 200,
            message = "meta配置应小于300"
    ) String meta;
    @TableField
    private @Length(
            max = 10,
            message = "状态长度应小于10"
    ) String status;
    @TableField
    private Long sortId;
    @TableField(
            fill = FieldFill.INSERT_UPDATE
    )
    private LocalDateTime updateTime;
    @TableField(
            exist = false
    )
    private RouteMeta routeMeta;

    public IamResource() {
    }

    public String getId() {
        return (String)super.getId();
    }

    public BaseEntity<String> setId(String id) {
        super.setId(id);
        return this;
    }

    public RouteMeta getRouteMeta() {
        if (V.notEmpty(this.routeMeta)) {
            return this.routeMeta;
        } else {
            return V.isEmpty(this.getMeta()) ? new RouteMeta() : (RouteMeta)JSON.parseObject(this.getMeta(), RouteMeta.class);
        }
    }

    public void setRouteMeta(RouteMeta routeMeta) {
        this.routeMeta = routeMeta;
        routeMeta = V.isEmpty(routeMeta) ? new RouteMeta() : routeMeta;
        this.setMeta(JSON.stringify(routeMeta));
    }

    public String[] getPermissionCodes() {
        return V.isEmpty(this.permissionCode) ? null : S.split(this.permissionCode);
    }

    public void setPermissionCodes(List<String> permissionCodes) {
        if (V.isEmpty(permissionCodes)) {
            this.setPermissionCode((String)null);
        }

        this.setPermissionCode(S.join(permissionCodes));
    }

    public String getTenantId() {
        return this.tenantId;
    }

    public String getAppModule() {
        return this.appModule;
    }

    public String getParentId() {
        return this.parentId;
    }

    public String getDisplayType() {
        return this.displayType;
    }

    public String getDisplayName() {
        return this.displayName;
    }

    public String getDisplayNameI18n() {
        return this.displayNameI18n;
    }

    public String getRoutePath() {
        return this.routePath;
    }

    public String getResourceCode() {
        return this.resourceCode;
    }

    public String getPermissionCode() {
        return this.permissionCode;
    }

    public String getMeta() {
        return this.meta;
    }

    public String getStatus() {
        return this.status;
    }

    public Long getSortId() {
        return this.sortId;
    }

    public LocalDateTime getUpdateTime() {
        return this.updateTime;
    }

    @JsonIgnore
    public IamResource setTenantId(final String tenantId) {
        this.tenantId = tenantId;
        return this;
    }

    public IamResource setAppModule(final String appModule) {
        this.appModule = appModule;
        return this;
    }

    public IamResource setParentId(final String parentId) {
        this.parentId = parentId;
        return this;
    }

    public IamResource setDisplayType(final String displayType) {
        this.displayType = displayType;
        return this;
    }

    public IamResource setDisplayName(final String displayName) {
        this.displayName = displayName;
        return this;
    }

    public IamResource setDisplayNameI18n(final String displayNameI18n) {
        this.displayNameI18n = displayNameI18n;
        return this;
    }

    public IamResource setRoutePath(final String routePath) {
        this.routePath = routePath;
        return this;
    }

    public IamResource setResourceCode(final String resourceCode) {
        this.resourceCode = resourceCode;
        return this;
    }

    public IamResource setPermissionCode(final String permissionCode) {
        this.permissionCode = permissionCode;
        return this;
    }

    public IamResource setMeta(final String meta) {
        this.meta = meta;
        return this;
    }

    public IamResource setStatus(final String status) {
        this.status = status;
        return this;
    }

    public IamResource setSortId(final Long sortId) {
        this.sortId = sortId;
        return this;
    }

    public IamResource setUpdateTime(final LocalDateTime updateTime) {
        this.updateTime = updateTime;
        return this;
    }
}
